package com.xuexiang.xuidemo.page.text;

import ohos.agp.components.Image;
import ohos.agp.components.Text;

import com.xuexiang.xui_lib.component.textview.marqueen.ExpandableTextComponent;
import com.xuexiang.xui_lib.util.LogUtils;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.page.base.BasePageAbilitySlice;
import com.xuexiang.xuidemo.page.base.Page;
import com.xuexiang.xuidemo.util.XToastUtils;

/**
 * 可伸缩折叠的TextView
 *
 * @since 2021-04-06
 */
@Page(name = "可伸缩折叠的TextView", action = "ExpandableTextAbilitySlice", ability = TextAbility.class)
public class ExpandableTextAbilitySlice extends BasePageAbilitySlice {
    private static final String TAG = "ExpandableTextAbilitySlice";
    ExpandableTextComponent expandableTextComponent;
    private Text text;
    private Image image;

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_text_expandabletext;
    }

    @Override
    protected void onActive() {
        super.onActive();
        text = (Text) findComponentById(ResourceTable.Id_expandable_text);
        image = (Image) findComponentById(ResourceTable.Id_expand_collapse);
        expandableTextComponent = (ExpandableTextComponent) findComponentById(ResourceTable.Id_expand_text_view);
        LogUtils.info(TAG, "puppet : running !initComponents");
        expandableTextComponent.findViews(text, image);
        expandableTextComponent.setText(getString(ResourceTable.String_etv_content_demo1));
        expandableTextComponent.setOnExpandStateChangeListener(
            (textView, isExpanded) -> XToastUtils.toast(isExpanded ? "Expanded" : "Collapsed"));
    }
}
